package com.ejd.web.vo.genl;

import java.io.Serializable;
import java.util.List;

import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.model.SelectItem;


import com.ejd.service.IProductUnitService;
import com.ejd.service.IStakeholderService;
import com.ejd.utils.MessageFactory;
import com.ejd.utils.SpringFacesUtil;
import com.ejd.web.bo.impl.Productunit;
import com.ejd.web.bo.impl.Stakeholder;
import com.ejd.web.constant.EjdConstants;
import com.ejd.web.constant.SpringBeanConstants;

@ManagedBean(name="existStakeholder")
@SessionScoped
public class ExistStakeholderBean implements Serializable {
	
	private static final long serialVersionUID = 5054087821033164858L;

	private SelectItem[] stakeholderItems;

	
	public SelectItem[] getStakeholderItems() {
		return stakeholderItems;
	}


	public void setStakeholderItems(SelectItem[] stakeholderItems) {
		this.stakeholderItems = stakeholderItems;
	}


	public ExistStakeholderBean() {
		
		IStakeholderService<Stakeholder,Long> stakeholderService = (IStakeholderService<Stakeholder,Long>)SpringFacesUtil.getSpringBean(SpringBeanConstants.STAKEHOLDER_SERVICE_BEAN_NAME);
		stakeholderService.setEntityClass(Stakeholder.class);
		stakeholderService.setPKClass(Long.class);
		List<Stakeholder> stakeholders = stakeholderService.getAll();
		SelectItem[] tempStakeholderItems = new SelectItem[stakeholders.size()];
		if (null != stakeholders && !(stakeholders.isEmpty())) {
			for (int i=0; i< tempStakeholderItems.length; i++) {
				Stakeholder stakeholder = (Stakeholder) stakeholders.get(i);
				tempStakeholderItems[i] = new SelectItem(stakeholder.getStakeholderId(),stakeholder.getShortName());
			}
		}
		this.setStakeholderItems(tempStakeholderItems);
	}
}
